package it.koutifaris.travianmap.utils;

import junit.framework.Assert;
import android.test.AndroidTestCase;

public class ModularBoundsTest extends AndroidTestCase {

	public void testUpperXBounds() {
		ModularBounds toroid = new ModularBounds(1, 5);
		Assert.assertEquals(1, toroid.module(5));
	}

	public void testLowerXBounds() {
		ModularBounds toroid = new ModularBounds(1, 5);
		Assert.assertEquals(1, toroid.module(1));
	}

	public void testPInBounds() {
		Assert.assertEquals(2, ModularBounds.modularCoords(1, 5, 2));
	}

	public void testPUnderBounds() {
		Assert.assertEquals(4, ModularBounds.modularCoords(1, 5, 0));
	}

	public void testPOverBounds() {
		Assert.assertEquals(2, ModularBounds.modularCoords(1, 5, 6));
	}

	public void testPOverBoundsNTimes() {
		int times = 4;
		int min = 1;
		int max = 5;
		int shift = 2;

		int width = max - min;
		Assert.assertEquals(shift, ModularBounds.modularCoords(min, max, times * width + shift));
	}

	public void testPunderBoundsNTimes() {
		int times = 3;
		int min = 1;
		int max = 5;
		int shift = 2;

		int width = max - min;
		Assert.assertEquals(shift, ModularBounds.modularCoords(min, max, -times * width + shift));
	}

	public void testNegativeBoundsPInBounds() {
		Assert.assertEquals(-3, ModularBounds.modularCoords(-5, -1, -3));
	}

	public void testNegativeBoundsPUnderBounds() {
		Assert.assertEquals(-2, ModularBounds.modularCoords(-5, -1, -6));
	}

	public void testNegativeBoundsPUpperBounds() {
		Assert.assertEquals(-4, ModularBounds.modularCoords(-5, -1, 0));
	}
}
